#ifndef TASKS_H
#define TASKS_H

#include <defs/global.h>
#include <QtCore>
#include <core/task.h>
#include <core/entityobject.h>

class TaskEntry : public Opl::Core::EntityObject
{
	Q_OBJECT
	Q_PROPERTY(QString name READ name NOTIFY nameChanged)
	Q_PROPERTY(Opl::Core::Task* task READ task)
	Q_PROPERTY(QUrl picture READ picture)
public:
	QString name() { return _name; }
	Opl::Core::Task* task() { return _task; }
	QUrl picture() { return _picture; }
	bool autodelete() { return _autodelete; }

	TaskEntry():
		_autodelete(true)
	{

	}

	TaskEntry(const QString& n, Opl::Core::Task* t, const QUrl& img, bool autodel):
		_name(n)
	  ,_task(t)
	  ,_picture(img)
	  ,_autodelete(autodel)
	{

	}
signals:
	void nameChanged();

private:
	Opl::Core::Task* _task;
	QString _name;
	bool _autodelete;
	QUrl _picture;
};

class DeclarativeTask;
O_PRIVATE_DECLARE(Tasks);
class Tasks : public Opl::Core::EntityObject {
    Q_OBJECT
public:
    Q_INVOKABLE Opl::Core::Task* startFile(const QString& fn);


	Q_PROPERTY(QDeclarativeListProperty<TaskEntry> tasks READ tasks DESIGNABLE false NOTIFY tasksChanged)
	Q_CLASSINFO("DefaultProperty", "tasks")

	Tasks(Opl::Core::EntityObject *parent);
	~Tasks();

	QDeclarativeListProperty<TaskEntry> tasks();


	bool start(Opl::Core::Task* task, QString name = QString());
	bool start(Opl::Core::Task* task, bool autodelete, QString name = QString());

public slots:
	Opl::Core::Task* start(const QUrl& url);
	void stop(const QString& uuid);
	void stopAll();

signals:

    void taskStarted(QString uuid);
    void taskFinished(QString uuid);

    void tasksChanged();

private slots:
    void taskDone();
private:    
    O_PRIVATE_DECLARE_MEMBER(Tasks)
};

#endif // TASKS_H

